/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package facade;

import app.TaskPooler;
import exception.RepositoryException;
import base.Task;
import base.UserPreferences;
import exception.TaskExistsException;
import exception.TaskNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import register.TaskRegister;
import register.UserPreferencesRegister;

/**
 *
 * @author tacio
 */
public class Facade {

    private static Facade facade = null;
    private TaskRegister taskRegister;
    private UserPreferencesRegister userPreferencesRegister;
   
    private Facade() throws RepositoryException{
        initRegisters();        
    }

    private void initRegisters() throws RepositoryException{
        this.taskRegister = new TaskRegister();
        this.userPreferencesRegister = new UserPreferencesRegister();
    }

    public static Facade getFacade() throws RepositoryException{
        if (facade == null) {
            facade = new Facade();
            return facade;
        } else {
            return facade;
        }
    }

    public void addTask(Task task) throws RepositoryException, TaskExistsException{
        taskRegister.add(task);
    }

    public void removeTask(String taskName) throws RepositoryException, TaskNotFoundException{
        taskRegister.remove(taskName);
    }

    public void updateTask(Task task) throws RepositoryException, TaskNotFoundException{
        taskRegister.update(task);
    }

    public Task search(String taskName) throws RepositoryException{
        return taskRegister.search(taskName);
    }

    public ArrayList<String[]> getTaskList() throws RepositoryException{
        return taskRegister.getTaskList();
    }

    public boolean downloadExists(Task task, URL torrentURL) throws RepositoryException {
         return taskRegister.downloadExists(task, torrentURL);
     }

     public ArrayList<String[]> getDownloadList() throws RepositoryException{
        return taskRegister.getDownloadList();
    }
 
    public UserPreferences getUserPreferences() throws RepositoryException {
        return userPreferencesRegister.getUserPreferences();
    }

     public void setUserPreferences(UserPreferences preferences) throws RepositoryException {
        userPreferencesRegister.setUserPreferences(preferences);
    }

}
